package com.xvyy.tingshu.search.runners;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * ClassName: DistributedBloomFilterInitRunner
 * Package: com.xvyy.tingshu.search.runners
 *
 * @Description:
 * @Author: xvyy
 * @Create: 2025/2/7 - 11:48
 * @Version: v1.0
 */
//@Component
public class DistributedBloomFilterInitRunnerTest implements ApplicationRunner , CommandLineRunner {

    /**
     * ApplicationRunner和CommandLineRunner的区别
     * 1、参数类型不同，ApplicationRunner的run方法解析命令行参数更加简单 CommandLineRunner的区别的run方法解析命令行参数复杂
     * 2、回调时机不同，ApplicationRunner的run方法会先调用 在调用 CommandLineRunner的区别的run
     * @param args
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 1. 可选参数
        Set<String> optionNames = args.getOptionNames();
        for (String optionName : optionNames) {
            System.out.println(optionName + " : " + args.getOptionValues(optionName));
        }
        // 2. 非可选参数
        List<String> nonOptionArgs = args.getNonOptionArgs();
        for (String nonOptionArg : nonOptionArgs) {
            System.out.println(nonOptionArg);
        }
        System.out.println("执行了DistributedBloomFilterInitRunner ApplicationRunner的run方法");
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("args = " + Arrays.toString(args));
        System.out.println("执行了DistributedBloomFilterInitRunner CommandLineRunner的run方法");
    }
}
